#include <iostream>

using namespace std;
/*
    多继承（环状继承）A->D,B->D,C->(A,B)例如：
    class D{};
    class B:public D{};
    class A:public D{};
    class C:public A,public B{};
    这个继承会使D创建两个对象，要解决上面的问题就要用虚拟继承格式
    格式： class 类名：virtual 集成方式 父类名
*/
class D
{
    public:
        D(){
            cout<<"D()"<<endl;
        }
        ~D(){
            cout<<"~D()"<<endl;
        }
        protected:
            int d;
};

class B:virtual public D{
    public:
        B(){cout<<"B()"<<endl;};
        ~B(){cout<<"~B()"<<endl;};
    protected:
        int b;
};

class A:virtual public D{
    public:
        A(){cout<<"A()"<<endl;};
        ~A(){cout<<"~A()"<<endl;};
    private:
        int a;
};

class C:public A,public B{
    public:
        C(){cout<<"C()"<<endl;};
        ~C(){cout<<"~C()"<<endl;};
    private:
        int c;
};
//与类同名的函数是构造函数
//~类名的是类的析构函数
int main()
{
    cout<< "helloworld!"<<endl;
    C c;
    cout<< sizeof(c) << endl;
    return 0;
}